/*
 * test_osock.c, under GNU GPL v2
 * 
 * Otter's Sockets Library test file
 * YOP: http://code.google.com/p/yopp2p/
 *
 * Jean Loup 'NC' Le Roux, 2007
 * nc@nightmare-creature.org
 * 
 */

#include "osocklib.h"
#include "../log/log.h"
#include <stdlib.h>

int main (void) {

  LOG_set_file("osocklib_test.log"); 
  LOG_set_level(LOG_ALL);
  
  msd_s myfirstsocket;
  npacket_s packet_to_send, packet_to_receive;
  char server_ip[] = "127.0.0.1";
  int i = 1;
  //int watch_retval; 
  
  char data_to_send[] = " May loose fly away ! ";
  packet_to_send.datap = (void*) &data_to_send;
  packet_to_send.datalen = sizeof(data_to_send);

  char data_to_receive[MAX_NPACK_SIZE];
  packet_to_receive.datap = (void*) &data_to_receive;
  packet_to_receive.datalen = 0;
  
  //char ip[] = "123.456.789.012";
  //OSOCK_same_subnet( ip ); 

  /*  
  OSOCK_connect( &myfirstsocket, TCP, NULL, 5005, SERVER );
  printf("tcp server created\n");
  OSOCK_validate_tcp_server( &myfirstsocket );
  printf("tcp server enabled\n");

  watch_retval = OSOCK_watch_connection( &myfirstsocket, 7 );
  printf("watch exited, return value: %d \n", watch_retval);
  
  
  while ( i < 10 ) {
  OSOCK_send( &myfirstsocket, &packet_to_send );
  printf( "\"%s\" sent %d time(s)\n", (char*) packet_to_send.datap, i);
  i++;
  sleep(1);
  }
  */ 
    
  OSOCK_connect( &myfirstsocket, TCP, server_ip , 5005, CLIENT ); 
  while ( i < 1000 ) {
  OSOCK_receive( &packet_to_receive, &myfirstsocket);
  printf(" \"%s\" received %d time(s)\n", (char*) packet_to_receive.datap, i); 
  i++;
  }

  OSOCK_disconnect( &myfirstsocket );
  
  LOG_close();

  return EXIT_SUCCESS;

}
